/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ImpuestosFrame.java
 *
 * Created on 01/30/2009, 08:54:18 PM
 */
package org.remolques.registros;

import org.mybeans.Sesion;
import org.mybeans.RegimenBeans;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import org.mybeans.PagosMensualesBeans;
import org.mybeans.ProcesarMorosidadIndividualRemolquesBeans;
import org.mybeans.RegimenRemolquesBeans;

import org.mybeans.RemolquesBeans;

import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;

/**
 *
 * @author avbravo
 */
public class RemolquesImpuestosInscripcionAgregarFrame extends javax.swing.JFrame {

    Sesion sesion;
    RegimenBeans regimenBeans;
    RemolquesBeans remolquesBeans;
    RegimenRemolquesBeans regimenRemolquesBeans;
    ProcesarMorosidadIndividualRemolquesBeans procesarMorosidadIndividualRemolquesBeans;
    PagosMensualesBeans pagosMensualesBeans;
    String idRegimenFormulario;
    private String RegimenFormulario = "";
    private int Anio;
    String[] arrayMes = sesion.getArrayMeses();
    private int NumeroMesInscripcion;
    private int NumeroMesActual;
    private int NumeroMesPago;
    private String Placa;
    private int IdRemolque;

    public int getNumeroMesActual() {
        return NumeroMesActual;
    }

    public void setNumeroMesActual(int NumeroMesActual) {
        this.NumeroMesActual = NumeroMesActual;
    }

    public int getNumeroMesInscripcion() {
        return NumeroMesInscripcion;
    }

    public void setNumeroMesInscripcion(int NumeroMesInscripcion) {
        this.NumeroMesInscripcion = NumeroMesInscripcion;
    }

    public int getAnio() {
        return Anio;
    }

    public void setAnio(int Anio) {
        this.Anio = Anio;
    }

    /** Creates new form ImpuestosFrame */
    public RemolquesImpuestosInscripcionAgregarFrame() {
        initComponents();
        sesion = new Sesion();
        sesion.setSeleccionado("no");
        /*
         * Fondo
         */

         
         
         

        jPanelFondo.setOpaque(false);
        setContentPane(jPanelFondo);
        /*
         * fondo
         */




        java.util.Calendar ca = java.util.Calendar.getInstance();
        java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());


        jXDatePickerFechaInscripcion.setDate(mydate);
        jXDatePickerFechaInscripcion.setFormats(new SimpleDateFormat("dd/MM/yyyy"));

        CargarSubGrupoRegimen();
        int year = ca.get(java.util.Calendar.YEAR);
        this.Anio = year;
        int nmes = ca.get(java.util.Calendar.MONTH);
        this.NumeroMesActual = nmes;

        AutoCompleteDecorator.decorate(this.jComboBoxSubGrupoRegimen);
        AutoCompleteDecorator.decorate(this.jComboBoxIdRegimen);
        AutoCompleteDecorator.decorate(this.jComboBoxMesPago);
        AutoCompleteDecorator.decorate(this.jComboBoxPeriodoPago);
        regimenBeans = new RegimenBeans();
       
        remolquesBeans = new RemolquesBeans();
         
        regimenRemolquesBeans = new RegimenRemolquesBeans();
        regimenRemolquesBeans.setAnio(year);
        regimenBeans = new RegimenBeans();

        procesarMorosidadIndividualRemolquesBeans = new ProcesarMorosidadIndividualRemolquesBeans();
        pagosMensualesBeans = new PagosMensualesBeans();
this.IdRemolque = sesion.getIdRemolque();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelFondo = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jComboBoxSubGrupoRegimen = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jComboBoxIdRegimen = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldValor = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldLimiteInferior = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldLimiteMaximo = new javax.swing.JTextField();
        jTextFieldMonto = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jButtonCalcular = new javax.swing.JButton();
        jTextFieldCantidad = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jXDatePickerFechaInscripcion = new org.jdesktop.swingx.JXDatePicker();
        jButtonAgregar = new javax.swing.JButton();
        jButtonCancelar = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        jComboBoxPeriodoPago = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        jComboBoxMesPago = new javax.swing.JComboBox();
        jButtonGuardar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("AGREGAR IMPUESTOS INICIALES");

        jLabel3.setText("Subgrupo");

        jComboBoxSubGrupoRegimen.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxSubGrupoRegimenItemStateChanged(evt);
            }
        });
        jComboBoxSubGrupoRegimen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxSubGrupoRegimenActionPerformed(evt);
            }
        });

        jLabel6.setText("Regimen");

        jComboBoxIdRegimen.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxIdRegimenItemStateChanged(evt);
            }
        });
        jComboBoxIdRegimen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxIdRegimenActionPerformed(evt);
            }
        });

        jLabel7.setText("Valor");

        jLabel8.setText("Inferior");

        jTextFieldLimiteInferior.setEditable(false);

        jLabel9.setText("Maximo");

        jTextFieldLimiteMaximo.setEditable(false);

        jLabel13.setText("Monto");

        jButtonCalcular.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/calculadora.jpeg"))); // NOI18N
        jButtonCalcular.setToolTipText("Calcular");
        jButtonCalcular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCalcularActionPerformed(evt);
            }
        });

        jTextFieldCantidad.setText("1");

        jLabel10.setText("Cantidad");

        jLabel14.setText("Fecha Inscripcion(dd/MM/AAAA)");

        jXDatePickerFechaInscripcion.setToolTipText("dia/mes/año");
        jXDatePickerFechaInscripcion.setLinkDay(new java.util.Date(1261630800000L));

        jButtonAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/insertarimpuesto.png"))); // NOI18N
        jButtonAgregar.setToolTipText("Agregar");
        jButtonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAgregarActionPerformed(evt);
            }
        });

        jButtonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonCancelar.setToolTipText("Regresar");
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });

        jLabel11.setText("Perido Pago");

        jComboBoxPeriodoPago.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Mensual", "Anual" }));
        jComboBoxPeriodoPago.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxPeriodoPagoActionPerformed(evt);
            }
        });

        jLabel12.setText("Mes Pago");

        jComboBoxMesPago.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));

        jButtonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/save.png"))); // NOI18N
        jButtonGuardar.setToolTipText("Guardar");
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelFondoLayout = new javax.swing.GroupLayout(jPanelFondo);
        jPanelFondo.setLayout(jPanelFondoLayout);
        jPanelFondoLayout.setHorizontalGroup(
            jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBoxIdRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 389, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanelFondoLayout.createSequentialGroup()
                                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                                        .addComponent(jTextFieldValor, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(28, 28, 28)
                                        .addComponent(jLabel8))
                                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                                        .addGap(1, 1, 1)
                                        .addComponent(jTextFieldCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jButtonCalcular)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel13)
                                .addGap(18, 18, 18)
                                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                                        .addComponent(jTextFieldLimiteInferior, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(6, 6, 6)
                                        .addComponent(jLabel9)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldLimiteMaximo, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jTextFieldMonto, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jComboBoxSubGrupoRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 473, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelFondoLayout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBoxPeriodoPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelFondoLayout.createSequentialGroup()
                                .addGap(45, 45, 45)
                                .addComponent(jButtonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelFondoLayout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(jLabel12)
                                .addGap(18, 18, 18)
                                .addComponent(jComboBoxMesPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelFondoLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 163, Short.MAX_VALUE)
                                .addComponent(jXDatePickerFechaInscripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanelFondoLayout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addComponent(jButtonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(24, 24, 24))
        );
        jPanelFondoLayout.setVerticalGroup(
            jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jComboBoxSubGrupoRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jComboBoxIdRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(jLabel9)
                        .addComponent(jTextFieldLimiteMaximo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldLimiteInferior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanelFondoLayout.createSequentialGroup()
                            .addComponent(jLabel10)
                            .addGap(12, 12, 12))
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonCalcular)
                            .addComponent(jLabel13)))
                    .addComponent(jTextFieldMonto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(jXDatePickerFechaInscripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jComboBoxPeriodoPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxMesPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelFondo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelFondo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxSubGrupoRegimenItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxSubGrupoRegimenItemStateChanged
}//GEN-LAST:event_jComboBoxSubGrupoRegimenItemStateChanged

    private void jComboBoxSubGrupoRegimenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxSubGrupoRegimenActionPerformed

        try {
            String temp = (String) jComboBoxSubGrupoRegimen.getSelectedItem();
            int posicion = temp.indexOf("|");

            int posfinal = 0;
            if (posicion <= 0) {
                posfinal = 0;
            } else {
                posfinal = posicion - 1;
            }

            temp = temp.substring(0, posfinal);

            CargarRegimen(temp);


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error  " + ex.getMessage(), "ComboBox SubGrupoRegimen ActionPerformed", JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_jComboBoxSubGrupoRegimenActionPerformed

    private void jComboBoxIdRegimenItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxIdRegimenItemStateChanged
        //      }
        //start = false;
}//GEN-LAST:event_jComboBoxIdRegimenItemStateChanged

    private void jComboBoxIdRegimenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxIdRegimenActionPerformed

        try {
            String temp = (String) jComboBoxIdRegimen.getSelectedItem();

            if (temp == null || temp.equals("")) {
                return;
            }
            int posicion = temp.indexOf("|");

            int posfinal = 0;
            if (posicion <= 0) {
                posfinal = 0;
            } else {
                posfinal = posicion - 1;
            }

            temp = temp.substring(0, posfinal);

            this.idRegimenFormulario = temp;
            ConsultarRegimen();


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error  " + ex.getMessage(), "ComboBox Regimen ActionPerformed", JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_jComboBoxIdRegimenActionPerformed

    private void jButtonCalcularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCalcularActionPerformed

        try {

            String sValor = this.jTextFieldValor.getText();
            double Valor = Double.parseDouble(sValor);
            if (Valor <= 0) {
                JOptionPane.showMessageDialog(this, "El valor no debe ser menor de 0.", "Mensaje", JOptionPane.WARNING_MESSAGE);
                this.jTextFieldValor.setText(String.valueOf(regimenBeans.getValor()));
                jTextFieldValor.requestFocus();
                return;
            }
            String can = this.jTextFieldCantidad.getText();
            if (can == null || can.equals("")) {
                JOptionPane.showMessageDialog(this, "ingrese la cantidad. Se ajustara a uno.", "Mensaje", JOptionPane.WARNING_MESSAGE);
                this.jTextFieldCantidad.setText("1");
                jTextFieldCantidad.requestFocus();
                return;
            }
            int cantidad = Integer.parseInt(can);
            if (cantidad <= 0) {
                JOptionPane.showMessageDialog(this, "La cantidad no debe ser negativa. Se ajustara a uno.", "Mensaje", JOptionPane.WARNING_MESSAGE);
                this.jTextFieldCantidad.setText("1");
                this.jTextFieldMonto.setText(String.valueOf(regimenBeans.getValor()));
                jTextFieldCantidad.requestFocus();
                return;
            }
            double monto = cantidad * Valor;
            Double LimiteInferior = Double.parseDouble(jTextFieldLimiteInferior.getText());
            Double LimiteSuperior = Double.parseDouble(jTextFieldLimiteMaximo.getText());

            if (monto < LimiteInferior) {
                JOptionPane.showMessageDialog(this, "El monto no debe ser menor que el limite inferior", "Mensaje", JOptionPane.WARNING_MESSAGE);
                this.jTextFieldMonto.setText(String.valueOf(regimenBeans.getValor()));
                this.jTextFieldCantidad.setText("1");
                return;
            }
            // if (monto > LimiteSuperior) {
            //    JOptionPane.showMessageDialog(this, "El monto no debe ser mayor que el limite superior", "Mensaje", JOptionPane.WARNING_MESSAGE);
            //    this.jTextFieldMonto.setText(String.valueOf(regimenBeans.getValor()));
            //    this.jTextFieldCantidad.setText("1");
            //   return;
            // }
            this.jTextFieldMonto.setText(String.valueOf(monto));
            regimenBeans.setValor(monto);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButtonCalcularActionPerformed

    private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_jButtonCancelarActionPerformed

    private void jButtonAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAgregarActionPerformed
        // TODO add your handling code here:
        sesion.setSeleccionado("si");
        dispose();
    }//GEN-LAST:event_jButtonAgregarActionPerformed

    private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed

        try {
           

            String IdRegimen = this.idRegimenFormulario;
            if (IdRegimen == null || IdRegimen.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese el codigo del regimen", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }


            String Regimen = this.idRegimenFormulario;
            if (Regimen == null || Regimen.equals("")) {
                JOptionPane.showMessageDialog(this, "seleccione un regimen", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String sValor = this.jTextFieldValor.getText();
            double Valor = Double.parseDouble(sValor);
            if (Valor <= 0) {
                JOptionPane.showMessageDialog(this, "El valor no debe ser menor de 0.", "Mensaje", JOptionPane.WARNING_MESSAGE);
                this.jTextFieldValor.setText(String.valueOf(regimenBeans.getValor()));
                jTextFieldValor.requestFocus();
                return;
            }
            String can = this.jTextFieldCantidad.getText();
            if (can == null || can.equals("")) {
                JOptionPane.showMessageDialog(this, "ingrese la cantidad. Se ajustara a uno.", "Mensaje", JOptionPane.WARNING_MESSAGE);
                this.jTextFieldCantidad.setText("1");
                jTextFieldCantidad.requestFocus();
                return;
            }
            int cantidad = Integer.parseInt(can);
            if (cantidad <= 0) {
                JOptionPane.showMessageDialog(this, "La cantidad no debe ser negativa. Se ajustara a uno.", "Mensaje", JOptionPane.WARNING_MESSAGE);
                this.jTextFieldCantidad.setText("1");
                return;
            }
            double monto = cantidad * Valor;
            Double LimiteInferior = Double.parseDouble(jTextFieldLimiteInferior.getText());
            Double LimiteSuperior = Double.parseDouble(jTextFieldLimiteMaximo.getText());

            if (monto < LimiteInferior) {
                JOptionPane.showMessageDialog(this, "El monto no debe ser menor que el limite inferior", "Mensaje", JOptionPane.WARNING_MESSAGE);
                this.jTextFieldMonto.setText(String.valueOf(regimenBeans.getValor()));
                this.jTextFieldCantidad.setText("1");
                return;
            }
            if (monto > LimiteSuperior) {
                JOptionPane.showMessageDialog(this, "El monto no debe ser mayor que el limite superior", "Mensaje", JOptionPane.WARNING_MESSAGE);
                this.jTextFieldMonto.setText(String.valueOf(regimenBeans.getValor()));
                this.jTextFieldCantidad.setText("1");
                return;
            }
            this.jTextFieldMonto.setText(String.valueOf(monto));


            String PeriodoPago = (String) this.jComboBoxPeriodoPago.getSelectedItem();
            if (PeriodoPago == null || PeriodoPago.equals("")) {
                JOptionPane.showMessageDialog(this, "seleccione el periodo pago", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String MesPago = (String) this.jComboBoxMesPago.getSelectedItem();

            if (MesPago == null || MesPago.equals("")) {
                JOptionPane.showMessageDialog(this, "seleccione el mes de pago", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            this.NumeroMesPago = sesion.getNumeroMes(MesPago);
            java.util.Date FechaDate = jXDatePickerFechaInscripcion.getDate();
            java.sql.Date FechaInscripcion = new java.sql.Date(FechaDate.getTime());
            if (FechaInscripcion == null) {
                JOptionPane.showMessageDialog(this, "Ingrese la fecha de inscripcion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jXDatePickerFechaInscripcion.requestFocus();
                return;
            }


            regimenRemolquesBeans.setIdRemolque(this.IdRemolque);
            regimenRemolquesBeans.setIdRegimen(IdRegimen);
            regimenRemolquesBeans.setValor(monto);
            regimenRemolquesBeans.setPeriodoPago(PeriodoPago);
            regimenRemolquesBeans.setMesPago(MesPago);
            regimenRemolquesBeans.setPagado("no");

            // java.util.Date myFecha = (java.util.Date) jXDatePickerFecha.getDate();
            // java.sql.Date fechaInscripcion = new java.sql.Date(myFecha.getTime());
            regimenRemolquesBeans.setFechaInscripcion(FechaInscripcion);
            if (regimenRemolquesBeans.VerificarExiste() == true) {
                JOptionPane.showMessageDialog(null, "Este impuesto ya fue asignado a este remolque", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
        /*
         *agregamos el registro
         */
            regimenRemolquesBeans.Agregar();
        /*
         *Agregar los pagosmensuales y anuales
         *verificamos el mes actual y el año.
         */
            java.util.Date myFecha2 = (java.util.Date) jXDatePickerFechaInscripcion.getDate();
            java.sql.Date date = new java.sql.Date(myFecha2.getTime());

            Calendar c = Calendar.getInstance();
            c.setTime(myFecha2);
            NumeroMesInscripcion = c.get(c.MONTH);


            PeriodoPago = PeriodoPago.trim();
            PeriodoPago = PeriodoPago.toLowerCase();
            pagosMensualesBeans.setAnio(Anio);
            pagosMensualesBeans.setId(String.valueOf(IdRemolque));
            pagosMensualesBeans.setTipoId("remolques");
            pagosMensualesBeans.setIdRegimen(IdRegimen);
            if (PeriodoPago.equals("mensual")) {

                String[] arrayMes = sesion.getArrayMeses();
                for (int m = 0; m < 12; m++) {
                /*
                 * si el numero de mes del combo es menor o igual que el
                 * mes actual en el array m, quiere decir que ese mes
                 * no ha sido pagado aun.
                 * si NumeroMesPago es mayor quiere decir que se inscribio mes despues y que
                 * no debe pagar ese mes.
                 */
                    if (NumeroMesInscripcion <= m) {
                        pagosMensualesBeans.setPagado("no");
                    } else {
                        pagosMensualesBeans.setPagado("ap");
                    }
                    pagosMensualesBeans.setMes(arrayMes[m]);
                    pagosMensualesBeans.setIdRecibo(0);
                    pagosMensualesBeans.setNumeroMes(m);
                    pagosMensualesBeans.AgregarPagosMensuales();
                }



            } else {
                pagosMensualesBeans.setMesPago(MesPago);
                pagosMensualesBeans.setIdRecibo(0);
                if (this.NumeroMesPago >= this.NumeroMesInscripcion) {
                    pagosMensualesBeans.setPagado("no");
                }

                pagosMensualesBeans.AgregarPagosAnuales();
            }

            regimenBeans.setValor(monto);
        /*
         * Aqui calculamos la morosidad, es un proceso de cierre muy basico.
         */

            if (PeriodoPago.equals("mensual") && this.NumeroMesInscripcion >= this.NumeroMesActual) {
                //No debe nada se esta inscribiendo ahora
                return;
            }
        /*
         * Falta validar cuando es un impuesto anual
         */


            procesarMorosidadIndividualRemolquesBeans.setAnio(this.Anio);
            procesarMorosidadIndividualRemolquesBeans.setNumeroMesActual(this.NumeroMesActual);
            procesarMorosidadIndividualRemolquesBeans.setMes(arrayMes[this.NumeroMesActual]);
            procesarMorosidadIndividualRemolquesBeans.setNumeroMesInscripcion(NumeroMesInscripcion);
            procesarMorosidadIndividualRemolquesBeans.setNumeroMesPago(NumeroMesPago);
            procesarMorosidadIndividualRemolquesBeans.setIdRemolque(this.IdRemolque);
            procesarMorosidadIndividualRemolquesBeans.setIdRegimen(IdRegimen);
            procesarMorosidadIndividualRemolquesBeans.setValor(Valor);
            procesarMorosidadIndividualRemolquesBeans.setPeriodoPago(PeriodoPago);
            procesarMorosidadIndividualRemolquesBeans.setTipoProcesoImpuestos("agregar");
            procesarMorosidadIndividualRemolquesBeans.ProcesarMorosidadDelImpuesto();
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error", "Boton Guardar()\nError " + ex.getMessage().toString());

        }
}//GEN-LAST:event_jButtonGuardarActionPerformed

    private void jComboBoxPeriodoPagoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxPeriodoPagoActionPerformed
        // TODO add your handling code here:
        try{
            String combo = (String)jComboBoxPeriodoPago.getSelectedItem();
            if (combo == null || combo.equals("")){

            }
            else{
                combo = combo.trim();
                if (combo.equals("Mensual")){
                    jComboBoxMesPago.setEnabled(false);
                }
                else{
                    jComboBoxMesPago.setEnabled(true);
                }
            }
        }catch(Exception ex){
                JOptionPane.showMessageDialog(this, "ComboPeriodo()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jComboBoxPeriodoPagoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new RemolquesImpuestosInscripcionAgregarFrame().setVisible(true);
            }
        });
    }

    private void CargarSubGrupoRegimen() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String sqlquery = "select idsubgruporegimen, subgrupo from subgruporegimen where idmunicipio='" + sesion.getIdmunicipio() + "' and activo='si' order by idsubgruporegimen";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            ResultSet rs = psquery.executeQuery();
            jComboBoxSubGrupoRegimen.removeAllItems();
            int count = 0;
            while (rs.next()) {
                String idsubgruporegimen = rs.getString("idsubgruporegimen");
                idsubgruporegimen = idsubgruporegimen + " | " + rs.getString("subgrupo");
                jComboBoxSubGrupoRegimen.insertItemAt(idsubgruporegimen, count);
                count++;
            }
            if (count != 0) {
                jComboBoxSubGrupoRegimen.setSelectedIndex(0);
            }


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error. CargarSubGrupoRegimen()", JOptionPane.ERROR_MESSAGE);
        }
    }

    /*
     *
     * Cargar el regimen
     */
    private void CargarRegimen(String idsubgruporegimen) {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            idsubgruporegimen = idsubgruporegimen.trim();
            String sqlquery = "select idregimen, valor, regimen from regimen where idmunicipio='" + sesion.getIdmunicipio() + "' and activo='si' and idsubgruporegimen='" + idsubgruporegimen + "' order by idregimen";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            ResultSet rs = psquery.executeQuery();
            jComboBoxIdRegimen.removeAllItems();
            int count = 0;
            while (rs.next()) {
                String idregimen = rs.getString("idregimen");
                idregimen = idregimen + " | " + String.valueOf(rs.getDouble("valor")) + " | " + rs.getString("regimen");
                jComboBoxIdRegimen.insertItemAt(idregimen, count);
                count++;
            }
            if (count != 0) {
                jComboBoxIdRegimen.setSelectedIndex(0);
            }


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error" + ex.getMessage(), "CargarRegimen() ", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void ConsultarRegimen() {
        try {
            String IdRegimen = idRegimenFormulario;
            if (IdRegimen == null || IdRegimen.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese el codigo del regimen", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            String sqlquery = "select regimen.* from regimen where regimen.idmunicipio = ? and idregimen = ?";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            psquery.setString(1, sesion.getIdmunicipio());
            psquery.setString(2, IdRegimen);
            ResultSet rs = psquery.executeQuery();
            rs.next();
            int x = rs.getRow();
            if (x == 0) {
                JOptionPane.showMessageDialog(this, "No existen registros de regimen con ese codigo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String activo = rs.getString("activo");
            if (activo.equals("no")) {
                JOptionPane.showMessageDialog(this, "Este regimen esta inactivo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String IdSubGrupoRegimen = rs.getString("idsubgruporegimen");
            String Regimen = rs.getString("regimen");
            double Valor = rs.getDouble("valor");
            double LimiteInferior = rs.getDouble("limiteinferior");
            double LimiteSuperior = rs.getDouble("limiteSuperior");

            if (Regimen == null || Regimen.equals("")) {
                JOptionPane.showMessageDialog(this, "El regimen esta en blanco", "Mensaje", JOptionPane.WARNING_MESSAGE);
                return;
            }
            regimenBeans.setIdRegimen(IdRegimen);
            regimenBeans.setIdSubGrupoRegimen(IdSubGrupoRegimen);
            regimenBeans.setRegimen(Regimen);
            regimenBeans.setValor(Valor);
            regimenBeans.setLimiteInferior(LimiteInferior);
            regimenBeans.setLimiteSuperior(LimiteSuperior);
            RegimenFormulario = Regimen;
            this.jTextFieldValor.setText(String.valueOf(Valor));
            this.jTextFieldLimiteInferior.setText(String.valueOf(LimiteInferior));
            this.jTextFieldLimiteMaximo.setText(String.valueOf(LimiteSuperior));
            this.jTextFieldMonto.setText(String.valueOf(Valor));
            jTextFieldCantidad.setText("1");


            repaint();

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "ConsultarRegimen() ", JOptionPane.ERROR_MESSAGE);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAgregar;
    private javax.swing.JButton jButtonCalcular;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JComboBox jComboBoxIdRegimen;
    private javax.swing.JComboBox jComboBoxMesPago;
    private javax.swing.JComboBox jComboBoxPeriodoPago;
    private javax.swing.JComboBox jComboBoxSubGrupoRegimen;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanelFondo;
    private javax.swing.JTextField jTextFieldCantidad;
    private javax.swing.JTextField jTextFieldLimiteInferior;
    private javax.swing.JTextField jTextFieldLimiteMaximo;
    private javax.swing.JTextField jTextFieldMonto;
    private javax.swing.JTextField jTextFieldValor;
    private org.jdesktop.swingx.JXDatePicker jXDatePickerFechaInscripcion;
    // End of variables declaration//GEN-END:variables
}
